package com.smarth.zhizulian.activity;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.smarth.zhizulian.app.BaseActivity;
import com.smarth.zhizulian.utils.KumaToast;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.PushAgent;

import io.reactivex.functions.Consumer;


/**
 * Created by KUMA on 2017/8/25.
 */

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_splash);
//        this.requestWindowFeature(Window.FEATURE_NO_TITLE); // 隐藏应用程序的标题栏，即当前activity的label
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 隐藏android系统的状态栏
        if (!this.isTaskRoot()) {
            Intent intent = getIntent();
            if (intent != null) {
                String action = intent.getAction();
                if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
                    finish();
                    return;
                }
            }
        }

        initSplash();
    }

    private void initSplash() {
        //延时跳转到主页面，splash用来做引导页
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                MainActivity.openClearTaskShowMission(SplashActivity.this, MainActivity.MODE_NORMAL);
//                TestActivity.open(SplashActivity.this);
            }
        }, 3000 * 1);

//        new RxPermissions(this)
//                .request(Manifest.permission.READ_EXTERNAL_STORAGE
//                        , Manifest.permission.WRITE_EXTERNAL_STORAGE
//                )
//                .subscribe(new Consumer<Boolean>() {
//                    @Override
//                    public void accept(Boolean aBoolean) throws Exception {
//                        if (aBoolean) {
//                            PictureSelector.create(mContext)
//                                    .openGallery(PictureMimeType.ofImage())
//                                    .selectionMode(PictureConfig.SINGLE)
//                                    .enableCrop(true)
//                                    .withAspectRatio(1, 1)
//                                    .forResult(PictureConfig.CHOOSE_REQUEST);
//                        } else {
//                            KumaToast.show(mContext, "请开通权限后重试");
//                        }
//                    }
//                });
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
